package com.qsl.ssyx.activity.api;

import com.qsl.ssyx.activity.service.ActivityInfoService;
import com.qsl.ssyx.activity.service.ActivityRuleService;
import com.qsl.ssyx.activity.service.CouponInfoService;
import com.qsl.ssyx.common.result.Result;
import com.qsl.ssyx.model.activity.CouponInfo;
import com.qsl.ssyx.model.order.CartInfo;
import com.qsl.ssyx.vo.order.CartInfoVo;
import com.qsl.ssyx.vo.order.OrderConfirmVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "服务调用接口-营销活动")
@RestController
@RequestMapping("/api/activity")
public class ActivityInfoApiController {

    @Autowired
    private ActivityInfoService activityInfoService;
    @Autowired
    private CouponInfoService couponInfoService;

    @ApiOperation("根据商品Ids获取促销信息")
    @PostMapping("inner/getActivityInfoBySkuId")
    public Map<Long, List<String>> getActivityInfoBySkuId(@ApiParam(value = "skuIds", required = true) @RequestBody List<Long> skuIdList) {
        Map<Long, List<String>> map = activityInfoService.getActivityInfoBySkuId(skuIdList);
        return map;
    }

    @ApiOperation("根据商品id和用户id获取优惠卷信息")
    @GetMapping("inner/getActivityInfoBySkuIdAndUserId/{skuId}/{userId}")
    public Map<String, Object> getActivityInfoBySkuIdAndUserId(@ApiParam(value = "商品Id", required = true) @PathVariable Long skuId,
                                                               @ApiParam(value = "userId", required = true) @PathVariable Long userId) {
        Map<String, Object> map = activityInfoService.getActivityInfoBySkuIdAndUserId(skuId, userId);
        return map;
    }

    @ApiOperation("根据购物车商品和用户id获取优惠卷和活动的信息")
    @PostMapping("inner/findCartActivityAndCoupon/{userId}")
    public OrderConfirmVo findCartActivityAndCoupon(@RequestBody List<CartInfo> cartInfoList,
                                                    @ApiParam(value = "userId", required = true) @PathVariable Long userId) {
        OrderConfirmVo orderConfirmVo = activityInfoService.findCartActivityAndCoupon(cartInfoList, userId);
        return orderConfirmVo;
    }

    @ApiOperation("促销活动相关信息")
    @PostMapping("/inner/findCartActivityList")
    List<CartInfoVo> findCartActivityList(@RequestBody List<CartInfo> cartInfoParamList) {
        List<CartInfoVo> cartInfoList = activityInfoService.findCartActivityList(cartInfoParamList);
        return cartInfoList;
    }


    @ApiOperation("根据购物车商品和优惠卷id获取优惠卷信息")
    @PostMapping("/inner/findRangeSkuIdList/{couponId}")
    CouponInfo findRangeSkuIdList(@RequestBody List<CartInfo> cartInfoList,
                                  @ApiParam(value = "couponId", required = true) @PathVariable Long couponId) {
        CouponInfo couponInfo = couponInfoService.findRangeSkuIdList(cartInfoList, couponId);
        return couponInfo;
    }

    @ApiOperation("根据用户id、优惠卷id、优惠卷与用户ID， 修改优惠卷状态-已使用")
    @GetMapping("inner/updateCouponInfoUseStatus/{couponId}/{userId}/{id}")
    boolean updateCouponInfoUseStatus(@ApiParam(value = "优惠卷id", required = true) @PathVariable Long couponId,
                                      @ApiParam(value = "用户id", required = true) @PathVariable Long userId,
                                      @ApiParam(value = "优惠卷与用户ID", required = true) @PathVariable Long id) {
        boolean flag = couponInfoService.updateCouponInfoUseStatus(couponId, userId, id);
        return flag;
    }
}
